package com.cipta.lomob;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.cipta.lomob.base.BaseActivity;

public class LomobLoginActivity extends BaseActivity{
	private Button btnLogin;
	private EditText edtUsername, edtPassword;
	private TextView txtForgotPassword;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lomob_login);
		
		initializeViews();
		initializeProcess();
		initializeActions();
	}
	
	@Override
	public void initializeViews() {
		// TODO Auto-generated method stub
		super.initializeViews();
		
		btnLogin = (Button)findViewById(R.id.btn_lomob_login);
		txtForgotPassword = (TextView)findViewById(R.id.txt_lomob_login);
		edtPassword = (EditText)findViewById(R.id.edt_lomob_login_password);
		edtUsername = (EditText)findViewById(R.id.edt_lomob_login_username);
	}
	
	@Override
	public void initializeProcess() {
		// TODO Auto-generated method stub
		super.initializeProcess();
		
		String login = "Tap here";
		txtForgotPassword.setText(login);
		txtForgotPassword.setTextColor(getResources().getColor(R.color.comand_text_color));
	}
	
	@Override
	public void initializeActions() {
		// TODO Auto-generated method stub
		super.initializeActions();
		btnLogin.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (edtPassword.getText().toString().equals("")||
						edtUsername.getText().toString().equals("")) {
					showLoginAlert();
				} else {
					MainActivity.toMainActivity(LomobLoginActivity.this);
					finish();
				}
			}
		});
		
		txtForgotPassword.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ForgotPasswordActivity.toForgotPasswordActivity(LomobLoginActivity.this);
			}
		});
	}
	
	public static void toLomobLoginActivity(Activity activity){
		activity.startActivity(new Intent(activity, LomobLoginActivity.class));
	}
	
	private void showLoginAlert(){
		final Dialog dialog = new Dialog(LomobLoginActivity.this);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_lomob_login);
		Button btnOk = (Button)dialog.findViewById(R.id.btn_dialog_login_);
		btnOk.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialog.dismiss();
			}
		});
		dialog.show();
	}
}
